import java.util.HashSet;
import java.util.Set;

class 最长连续序列 {
    public static void main(String[] args) {
        System.out.println(longestConsecutive(new int[]{100, 4, 200, 1, 3, 2}));
    }
    public static int longestConsecutive(int[] nums) {
        //将数组元素存入set集合中，去除重复元素
        Set<Integer> set=new HashSet<>();
        for (int num : nums) {
            set.add(num);
        }
        int len=0;//记录最长序列长度
        int constantlen=0;
        for (Integer num : set) {
            if(!set.contains(num-1)){
                constantlen=1;
                while(set.contains(++num)) constantlen++;
            }
           len=Math.max(constantlen,len);
        }
        return len;
    }
}